<template>
  <el-card>
    <div class="header-box"></div>

    <div class="flex-content">
      <el-table
        v-loading="isLoading.table"
        :data="dataList"
        style="width: 100%"
      >
        <el-table-column align="center" label="参数名称" prop="name">
        </el-table-column>

        <el-table-column align="center" label="参数值" prop="value">
        </el-table-column>

        <el-table-column align="center" label="备注" prop="remark">
        </el-table-column>

        <el-table-column align="center" label="操作" width="150">
          <template v-slot="{ row }">
            <el-button size="mini" type="primary" @click="handleEdit(row)">
              编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 添加与修改-->
    <Edit v-if="isDialog.edit" :info="dataInfo" @close="closeDialog"></Edit>
  </el-card>
</template>

<script>
import { lists as getList } from "@/api/param";
import Edit from "./components/edit";

export default {
  name: "Param",
  components: {
    Edit,
  },
  data() {
    return {
      // 查询条件
      queryInfo: {
        pg_id: 1,
      },
      // 总页数
      totalCount: 0,
      // 列表
      dataList: [],
      // 详情
      dataInfo: {},
      // 加载
      isLoading: {
        table: false,
      },
      // 弹窗
      isDialog: {
        edit: false,
      },
      // 防抖
      queryId: +new Date(),
    };
  },
  created() {
    this.getData();
  },
  methods: {
    // 列表
    getData() {
      this.isLoading.table = true;
      this.queryId++;
      let queryId = this.queryId;
      getList(this.queryInfo)
        .then((res) => {
          if (queryId !== this.queryId) {
            return;
          }
          this.dataList = res.data.list;
        })
        .finally(() => {
          this.isLoading.table = false;
        });
    },
    // 编辑
    handleEdit(row) {
      this.dataInfo = row;
      this.isDialog.edit = true;
    },
    // 重置页面数据
    handleResetPage() {
      this.queryInfo.page = 1;
      this.getData();
    },
    //关闭
    closeDialog(val) {
      if (!val) {
        this.getData();
      }
      this.isDialog.edit = false;
    },
  },
};
</script>

<style lang="scss" scoped></style>
